unit IBXUtils;

interface

uses SysUtils, IBHeader, IBIntf, IB, IBSQL;

function GetSqlInfo(sqlObject: TIBSQL; InfoType: integer): String;

implementation

function GetSqlInfo(sqlObject: TIBSQL; InfoType: integer): String;
var
  result_buffer: array[0..16384] of Char;
  result_length, i: Integer;
  info_request: Char;
begin
  if (not sqlObject.Prepared) or
     (not (sqlObject.SQLType in [SQLSelect, SQLSelectForUpdate,
       {TODO: SQLExecProcedure, }
       SQLUpdate, SQLDelete])) then
    result := ''
  else begin
    info_request := Char(InfoType);
    with sqlObject do begin
      Call(isc_dsql_sql_info(StatusVector, @Handle, 2, @info_request,
                             SizeOf(result_buffer), result_buffer), True);
      if (result_buffer[0] <> info_request) then
        raise Exception.Create('isc_dsql_sql_info failed.');
      result_length := isc_vax_integer(@result_buffer[1], 2);
      SetString(result, nil, result_length);
      for i := 1 to result_length do
        result[i] := result_buffer[i + 2];
      result := Trim(result);
    end;
  end;
end;

end.
